<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="../../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=emulateIE7"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="${ctx}/css/sapar.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css"/>
    <link href="${ctx}/css/select2.min.css" rel="stylesheet" />


    <style type="text/css">
        td {
            text-align: center;
        }
    </style>
</head>
<body>
<div class="tab-content-item" id="app">

    <audio src="../../audio/Beep_Short.mp3" id="audio"></audio><!-- 成功提示音 -->
    <audio src="../../audio/Alarm_Clock (1).mp3" id="audio1"></audio><!-- 失败提示音 -->
        <div class="kv-item clearfix" >


            <div class="kv-item clearfix">
                <div class="kv-item-content">
                    <%--<label><span class="impInfo">*</span>科室：</label>--%>
                    <%--<span>手术室</span>--%>
                    <%--<select id="packageDepartid" name="packageDepartid" onChange="showPack(true)">--%>
                        <%--<c:if test="${deptList !=null}">--%>
                            <%--<option value="0">请选择科室</option>--%>
                            <%--<c:forEach items="${deptList }" var="deptment">--%>
                                <%--<option  <c:if test="${selected==deptment.departmentId}">selected</c:if>  value="${deptment.departmentId}">${deptment.departmentName}</option>--%>
                            <%--</c:forEach>--%>
                        <%--</c:if>--%>
                    <%--</select>--%>
                </div>
                <%--<div class="kv-item-content">--%>
                    <%--<label>包筛选：</label>--%>
                    <%--<div class="kv-item-content" style="line-height:30px;">--%>
                        <%--<input style="width: 100px" name="packageName" id="packageName" class="gui-input" placeholder="包简码" type="text" value="">--%>
                    <%--</div>--%>
                <%--</div>--%>
                <div class="kv-item-content" style="padding-left: 400px">
                    <a   href="javascript:;" class="sapar-btn sapar-btn-recom query-btn"
                         @click="gaowen">高温</a>
                    <a   href="javascript:;" style="margin-left: 20px" class="sapar-btn sapar-btn-recom query-btn"
                         @click="diwen">低温</a>
                    <a   href="javascript:;" style="margin-left: 20px" class="sapar-btn sapar-btn-recom query-btn" id="baocun"
                        onclick="do_save()">保存</a>
                </div>
            </div>

        </div>
        <form class="package">
        <div class="table" >
            <!--表格具体内容-->
            <div class="table-box">
                <table id="tbpck">
                    <thead>
                    <tr>
                        <th>全选<input type="checkbox" id="quanxuan" name="quanxuan"/></th>
                        <th>包名称</th>
                        <th>包灭菌方式</th>
                        <th>数量</th>
                        <%--<th>灭菌数量</th>--%>
                    </tr>
                    </thead>
                    <tbody class="body_list" id="body_list">
                        <tr v-for="package in packageImformationList">
                            <td><input type="checkbox" name="key"/></td>
                            <td v-bind:data="package.packageTiaomas">{{package.tbPackageMuban.packageName}}</td>
                            <td>{{dictmap[package.tbPackageMuban.packageMiejunFangshi].dictName}}</td>
                            <td><input style="text-align: center" type="number" name="packageNum" v-bind:value="package.packageNum"/></td>
                            <%--<td><input type="number" onchange="jugeNum()" style="text-align: center" name="miejunNum"/></td>--%>
                        </tr>
                    </tbody>
                </table>
            </div>
            <%--<div>--%>
                <%--<input id="leftPage" class="butLeft" type="button" value="上一页"/>--%>
                <%--<input id="rightPage" class="butRight" type="button" value="下一页"/>--%>
                <%--<span>到第&nbsp;</span><input id="goPage" class="textBox" type="text" value="1"/><span--%>
                    <%--style="margin-left: 4px;">页&nbsp;</span>--%>
                <%--<input id="sureBut" class="sure" type="button" value="确定"/>--%>
                <%--<span>共</span><span class="totalPages" id="totalNum">0</span><span>&nbsp;页</span>--%>
            <%--</div>--%>
        </div>
        </form>
</div>

</body>
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/vue.min.js"></script>
<script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>
<%@ include file="../../../js.jsp" %>
<script type="text/javascript">

//    window.onload = function () {
//        $("#wanglantiaoma").focus();
//    };
    <%--var data = ${packages};--%>
    <%--shuzi(data);--%>
    $(function () {

        $("#quanxuan").click (function () {
            debugger
            var that = $(this);
            var flag = true;
            if(that.prop('checked')){
                flag = true;
            }else{
                flag = false;
            }
            $(".body_list").find("input[name='key']").each(function () {
                ck = $(this);
                if (flag) {
                    ck.prop('checked', true);
                } else {
                    ck.prop('checked', false);
                }
            });
        })

//        $('select').select2();

        $("#back").click(function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });
        $("#save").click(function () {
            do_save();
        });

//        $(document).keydown(function (event) {
//            var oPlay0 = document.getElementById("audio");
//            var oPlay1 = document.getElementById("audio1");
//            var packageName = $("input[name='packageName']").val();
//            if (event.keyCode == 13) {
//                debugger
//                if ($("#packageName").is(":focus") ) {
//                    showPack(false);
//                    $("#wanglantiaoma").focus();
//                }
//            }
//        });


    });
//
//    var oPlay0 = document.getElementById("audio");
//    var oPlay1 = document.getElementById("audio1");
//
//    var vm = new Vue({
//        el:'#app',
//        data : {
//            huishouWanglanTiaoma: '',
//            huishouWanglanMingcheng: '',
//        },
//        methods : {
//            enterFun: function () {
//                var that = this;
//                if ($("#wanglantiaoma").is(":focus") && !isNullOrEmpty(that.huishouWanglanTiaoma)) {
//                    $.get("/wutiaoma/findwanglan.do?huishouWanglanTiaoma=" + that.huishouWanglanTiaoma,function(data){
//                        if (data.status == true) {
//                            oPlay0.play();
//                            that.huishouWanglanMingcheng = data.zsWanglan.wlMingcheng;
//                            that.addpackage();
//                        }else if (data.status == false) {
//                            oPlay1.play();
//                            that.huishouWanglanTiaoma = "";
//                            that.huishouWanglanMingcheng = "";
//                        }
//                    })
//
//                }
//
//
//            },
//        }
//    })


    <%--function showPack(data) {--%>
        <%--if(data==true){--%>
            <%--$("#packageName").val("");--%>
        <%--}--%>
        <%--$("#packageName").focus();--%>
        <%--var url = "${ctx}/wutiaoma/findHuishouPackageByDepart.do?packageCode=" + $("#packageName").val() + "&packageDepartid=" + $("#packageDepartid").val();--%>
        <%--$.ajax({--%>
            <%--type: "POST",--%>
            <%--url: url,--%>
            <%--data: $('#dataHuiShouForm').serialize(),// 你的formid--%>
            <%--error: function (request) {--%>
                <%--layer.alert("网络故障，请稍后再试!");--%>
            <%--},--%>
            <%--success: function (datas) {--%>
                <%--if (datas.status == "true") {--%>
                    <%--var data = datas.packages;--%>
                    <%--shuzi(data);--%>


                <%--}--%>
            <%--}--%>
        <%--});--%>
    <%--}--%>

//    function shuzi(data){
//        $("#tbpck tbody").empty();
//        var str = "";
//        for (var i = 0; i < data.length; i++) {
//            var dep = data[i].tbDepartment;
//            var deptname;
//            if (dep != null) {
//                deptname = dep.departmentName;
//            } else {
//                deptname = "";
//            }
//            str += '<tr><td>' + deptname + '</td><td class="text-left">' + data[i].packageName + '</td><td><input type="hidden" name="deptName" value="' + deptname + '"/><input type="hidden" name="pid" value="' + data[i].packageId + '"/><input style="text-align:center" type="text" name="key" maxlength="3" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" class="gui-input"/><input type="hidden" name="pname" value="' + data[i].packageName + '"/></td></tr>'
//        }
//        $("#tbpck tbody").append(str);
//    }


    function do_save() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        var rtnJson = new Array();
        var check = true;
//        var options = $("#packageDepartid option:selected");
//        if(options==null){
//            alert("请选择科室");
//        }
//        var huishouWanglanTiaoma = $("#wanglantiaoma").val();
//        var huishouWanglanMingcheng = $("#wanglanMingcheng").val();
//        var keshi = $("#packageDepartid").val()
//        if (keshi != "0") {
//            var keshiName = $("#packageDepartid").find("option:selected").text();
//        }else if(keshi == "0"){
//            check = false;
//            alert("请选择科室进行回收，方便统计");
//        }
//        if(""==huishouWanglanTiaoma){
//            alert("请录入网篮")
//            check = false
//        }
//        if(""==huishouWanglanMingcheng){
//            alert("请录入正确的网篮")
//            check = false
//        }


        $(".body_list").find("input[name='key']:checked").each(function () {
            debugger
            var val = $(this).parent().next().next().next().find("input[name='packageNum']").val();
            var miejunFangshi = $(this).parent().next().next().text();
            var packageName = $(this).parent().next().text();
            var packageTiaomaData = $(this).parent().next().attr("data");
            var tiaoArr = new Array();
            tiaoArr = packageTiaomaData.split(",");
            if (val != '') {
                for(var i=0;i<val;i++){
                    var obj = new Object();
                    obj.packageName = packageName;
                    obj.miejunFangshi = miejunFangshi;
                    obj.packageTiaoma  = tiaoArr[i];
                    rtnJson.push(obj);
                }
            }
        });
//        $('input[name="packageNum"]').each(function () {
//            var val = $(this).val();
//            var miejunFangshi = $(this).parent().prev().text();
//            var packageName = $(this).parent().prev().prev().text();
//            var packageTiaomaData = $(this).parent().prev().prev().attr("data");
//            var tiaoArr = new Array();
//            tiaoArr = packageTiaomaData.split(",");
//            if (val != '') {
//                for(var i=0;i<val;i++){
//                    var obj = new Object();
//                    obj.packageName = packageName;
//                    obj.miejunFangshi = miejunFangshi;
//                    obj.packageTiaoma  = tiaoArr[i];
//                    rtnJson.push(obj);
//                }
//            }
//        });

        parent.callbackData(rtnJson);
        parent.layer.close(index);


    }

var vm = new Vue({
    el:"#app",
    data:{
        packageImformationList:[],
        dictmap:{},
    },
    created:function () {
        this.load();
//        setInterval(function () {
//            vm.load();
//        },20000)

    },

    methods: {

        diwen:function () {
            this.load(2);
        },
        gaowen:function () {
            this.load(1);
        },

        load:function(data1) {
            var type = 0;
            if(data1!=null&&!isNaN(data1)){
                type = data1;
            }
            $.get("/miejun/miejunAddPackage?type="+type, function (data) {
                if (data.status == true) {
                    vm.packageImformationList = data.packageImformations;
                    vm.dictmap = data.dictmap;
//                    vm.packageImformationList = data.packageImformations;
//					console.log(vm.packageImformationList);
                }
            })
        },
        showmingxi:function (id) {
            layer.open({
                type: 2,
                title: '包明细',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area : ['800px' , '520px'],
                content: '${ctx}/miejun/findQixieList.do?id='+id
            });
        },

    }
})

//    function jugeNum() {
//        debugger
//        var that = this;
//        var text1 = $(that).val();
//        var text2 = $(that).parent().prev().find("input[name='packageNum']").val();
//        if(text1>text2){
//            $(that).val(text2);
//        }
//        if(text1<=0){
//            $(that).val(0);
//        }
//
//    }

    //判断是否为空
    function isNullOrEmpty(strVal) {
        if (strVal != null) {
            strVal = strVal.replace(/(^\s*)|(\s*$)/g, "");
        }
        if (strVal == '' || strVal == null || strVal == undefined) {
            return true;
        } else {
            return false;
        }
    }

</script>
</html>